<template>
  <div class="selfintro-container">
    <div class="input-section">
      <label>请输入你的自我介绍：</label>
      <textarea
        v-model="selfIntroContent"
        placeholder="请在这里输入你的自我介绍..."
        rows="8"
      ></textarea>
      <button
        @click="submitSelfIntro"
        :disabled="!selfIntroContent.trim()"
      >
        获取评价
      </button>
    </div>

    <!-- 加载状态 -->
    <div class="loading" v-if="isLoading">
      正在分析您的自我介绍，请稍候...
    </div>

    <!-- 评价结果 -->
    <div class="evaluation-result" v-if="evaluationResult">
      <div class="score-section">
        <span>评分：1</span>
<!--        <span class="score">{{ evaluationResult.score }}/100</span>-->
      </div>

      <div class="feedback-section">
        <h4>评价与建议：</h4>
        <div class="feedback-content">
          {{ evaluationResult.answer }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from '../services/api'

export default {
  name: 'SelfIntro',
  data() {
    return {
      conversation_id: "0",
      selfIntroContent: '', // 自我介绍内容
      isLoading: false, // 加载状态
      evaluationResult: null ,// 评价结果
      positionId : 1
    }
  },
  methods: {
    // 提交自我介绍获取评价
    async submitSelfIntro() {
      if (!this.selfIntroContent.trim()) return

      try {
        this.isLoading = true
        this.evaluationResult = null
        const requestData = {
          position_id: this.positionId, // 动态获取职位ID的方法
          self_intro: this.selfIntroContent, // 使用用户输入
          conversation_id: this.conversation_id // 可能为null（首次请求）
        };
        // 调用API获取评价
        // alert('获取数据中')
       const response = await api.selfIntro.evaluate(requestData);
        // if (response.data.success) {
          this.evaluationResult = response.data
          // alert(response.data)
        // }
      } catch (error) {
        console.error('获取自我介绍评价失败:', error)
        alert(`请求错误: ${error.response?.data?.detail || error.message}`)
      } finally {
        this.isLoading = false
      }
      alert('获取数据成功')
    }
  }
}
</script>

<style>
.selfintro-container {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.input-section {
  margin-bottom: 20px;
}

.input-section textarea {
  width: 100%;
  padding: 10px;
  margin: 10px 0;
  border: 1px solid #ddd;
  border-radius: 4px;
  resize: vertical;
}

.input-section button {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.input-section button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.loading {
  text-align: center;
  padding: 20px;
  color: #666;
}

.evaluation-result {
  margin-top: 20px;
  padding: 15px;
  border: 1px solid #eee;
  border-radius: 4px;
}

.score-section {
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.score {
  font-size: 1.5em;
  font-weight: bold;
  color: #42b983;
  margin-left: 10px;
}

.feedback-section {
  margin-top: 15px;
}

.feedback-content {
  margin-top: 10px;
  line-height: 1.6;
  color: #333;
}
</style>